/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package web.usuarios;

import Persistencia.*;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import controladores.*;
import dominio.InformeDomain;
import java.util.HashMap;
import java.util.Map;

public class ControladorSimpleInforme extends SimpleFormController{

    ControladorInforme controlador = new ControladorInforme();
    ControladorSesion controladorSes = new ControladorSesion();
    InformeDomain obj;

    @Override
    public ModelAndView onSubmit(Object command) throws ServletException {
        obj = ((InformeDomain) command);
        controlador.setInformeD(obj);
        System.out.println("Guardar");
        String res = controlador.guardarInforme();
        Map<String, Object> modelo = new HashMap();
        if(res.split(" ")[0].equalsIgnoreCase("Se")){
            modelo.put("mensajeOk", res);
            modelo.put("mensajeNo", "");
            Sesion se=controladorSes.encontrarSesion(obj.getIdSesion());
            modelo.put("direccion", "IngresarInforme.htm?id_fisio="+((Fisioterapeuta)se.getFisioterapeuta()).getIdFisioterapeuta());
            return new ModelAndView("resultadoValidator","model",modelo);
        }else{
            modelo.put("mensajeOk", "");
            modelo.put("mensajeNo", res);
            Sesion se=controladorSes.encontrarSesion(obj.getIdSesion());
            modelo.put("direccion", "IngresarInforme.htm?id_fisio="+((Fisioterapeuta)se.getFisioterapeuta()).getIdFisioterapeuta());
            return new ModelAndView("resultadoValidator","model",modelo);
        }
    }

    protected Object formBackingObject(HttpServletRequest request) throws ServletException {
        InformeDomain log = new InformeDomain();
        return log;
    }

    public void setControladorInforme(ControladorInforme productManager) {
        this.controlador = productManager;
    }

    public ControladorInforme getControladorInforme() {
        return controlador;
    }
    
    @SuppressWarnings("unchecked")
    protected Map referenceData(HttpServletRequest request) throws Exception {
        Map referenceData = new HashMap();
        if(request.getParameter("id_fisio")!=null){
            referenceData.put("listSesion", controladorSes.encontrarMisSesiones(request.getParameter("id_fisio")));
        }
        return referenceData;
    }

}
